import Direction from './direction.js'
import MoveableEntity from './Moveable.js'
import Rocket from './Rocket.js'

export default class Tank extends MoveableEntity {
  constructor(x, y, width, height, imgSrc = '../assets/tank-up.png', life = 100, direction = Direction.TOP, speed = 3) {
    super(x, y, width, height, imgSrc, life, direction, speed)
    this.sprites = ['./assets/tank-up.png', './assets/tank-left.png', './assets/tank-down.png', './assets/tank-right.png']
    this.attack = 25
    this.readyShoot = true;
    this.shootInterval = 1500;
    this.maxLife = this.life;
  }

  shoot() {
    if (this.readyShoot) {
      this.readyShoot = false;
      setTimeout(() => {
        this.readyShoot = true;
      }, this.shootInterval);
      let rocket = new Rocket(this)
      rocket.owner = this
      return rocket
    }
  }
  
  drawLifeBar(context){
    context.fillStyle = '#eee';
    context.fillRect(this.x,this.y + 10,this.width,8);
    context.fillStyle = '#9a0909';
    context.fillRect(this.x+1,this.y + 11,this.width-1,6);
    context.fillStyle = '#f00';
    context.fillRect(this.x+1,this.y + 11,(this.width - 2) * (this.life / this.maxLife),6);
    
  }
}
